package com.lovi.homework;

import java.util.ArrayList;
import java.util.List;

/**
 * 使用ArrayList 完成对 对象 Car {name, price} 的各种操作
 * 1.add:添加单个元素
 * 2.remove:删除指定元素
 * 3.contains:查找元素是否存在
 * 4.size:获取元素个数
 * 5.isEmpty:判断是否为空
 * 6.clear:清空
 * 7.addAll:添加多个元素
 * 8.containsAll:查找多个元素是否都存在
 * 9.removeAll：删除多个元素
 * 使用增强for和 迭代器来遍历所有的car , 需要重写 Car 的toString方法
 */
public class Homework04_ {
    public static void main(String[] args) {
        List<Car> carlist =  new ArrayList<Car>();
        Car car1 = new Car("宝马", 500000);
        carlist.add(car1);
        Car car2 = new Car("奔驰", 400000);
        carlist.add(car2);
        carlist.add(new Car("法拉利",400000));
        carlist.add(new Car("路虎",500000));
        carlist.add(new Car("劳斯莱斯",4000000));
        System.out.println(carlist);
        carlist.remove(car1);
        System.out.println(carlist);
        System.out.println(carlist.contains(car2));
        System.out.println(carlist.size());
        System.out.println(carlist.isEmpty());
//        carlist.clear();
        System.out.println(carlist);
        ArrayList<Car> list = new ArrayList<>();
        list.add(car1);
        list.add(car2);

        carlist.addAll(list);
        System.out.println(carlist);
        System.out.println(carlist.containsAll(list));
        carlist.removeAll(list);
        System.out.println(carlist);


    }

}
